In here are the list of things I did for a particular hour or day. Also included here are the screenshots of games I played, or videos I watched or listened to, or just random things I stumbled upon. I'll occasionally write down what I'm thinking, or things I'm planning to do.
Worked on SN, I fixed the datetime so that it server-renders the date with UTC format, then converts that to localtime on the client side. I also added some textbox to easily view HN URLs.
I also looked at the fly logs why my cached json arent' working, it seems that they get deleted before the scheduled time. The logs says it periodically shutdowns the machine when the server is inactive. The fix is to use actual fly.io volumes for persistent storage.
I did some changes so that the lua code is compiled and preloaded. Supposedly this should reduce memory usage. And I think the average request time went down too, sort of.
Aha, I managed to deploy slacker news on fly.io surprisingly without much problem, now I can use it on my phone too. I have unused 500 fly.io credits that I got as a bonus for applying for a job at fly.io. Unfortunately, I got rejected, but at least I got free credits in return.
I wonder how long those $500 credit will last with my shitty app though. More importantly, I hope it doesn't get ddos'ed and put me in a massive debt? I recently read something like that, I can't remember the HN thread specifically.
Looking at my logs, it has been 14 days now since I started working on SN Err, the lua markdown library I'm using can't handle anchor # inside a link. Oh well.
Look back further, it has been more than a month now since I started logging my daily activites. I think I'll review it this weekend to get an idea what I need to change or improve on. I wasn't actually consistent with logging what I did for a day. What was logged was mostly my time on the computer, and not much else outside that. Well, there's not much else to say when it comes to my daily routine. I live in a tiny hikikomori NEET world.
Worked on SN, fixed some filesystem errors when creating a release build. There's definitely a bunch of added complexity by having a self-contained binary with the assets embedded, not sure if this is worth it. For now, I managed to make it work, I fixed the errors by replacing direct calls to os.Stat with my own fsStat(fs, filename).
I'm more or less almost done with the project, it's quite usable with its current state. I will be using this to read HN from now on.
My original goal was to create an HN clone to test my lua templating library. But creating an HN frontend works as well. I'm convinced using lua as an alternative templating engine works quite well, I might actually use it for more web projects in the future.
I'm still considering whether I should still try creating a full HN clone. It's not actually easy running a forum. For one, I don't have the (financial) resources to maintain it. Second, no one will use it but me. Third, it might get defaced or hacked quite easily. Despite all that, I feel like just doing it anyway. Try reduce server load, I could aggresively just cache everything, and just update the site for one or two times a day. Or not.
For now, I think I'll continue watching that video titled "Godot 4 - Tiled Dungeon Environment From Scratch".
I did plenty of stuffs today with SN, I added showing the comment chain (post context) and top frequent participants in a thread. I also added some cache clearing every 30 minutes, that way, I will only be forced to revisit a thread after half an hour, instead of compulsively checking and rechecking a thread every other minute.
The messiest code is the UI lua/html code, which isn't really unexpected. On the positive side, it's quite easy to modify or add new changes. And it still performs relatively well, less or around 100ms per 100 comments. Sure, text/template might be way, way faster, but it's not as flexible, or even quite painful to use.
The external http request are still by far the slowest though, the filesystem caching is required.
Well, some way or the other, I managed to make the SN mobile friendly-ish, it's now useable at least. The auto-adjusting font-size is pretty maddening though when on mobile. The rem unit is supposed to make the font-size relative to the root font-size, so why is some texts are still changing and appears smaller than the rest?
As it turns out, there's an exception and I have to explicitly set `text-size-adjust: none` to disable this behaviour. Some say this isn't a CSS best practice, but screw that.
This early afternoon, I also made some changes in the backend, fixed and simplified some problematic code that's causing race conditions. I also added an option to cache loaded lua modules, to speed things a little.
The hecking fuck, nothing's working. What arcane combination of symbols must I arrange to make media queries work on my phone. Sometime it works, but not actually. The documentation and articles made it sound easy, but the sample codes doesn't even work. Then again, maybe it's just my phone's outdated browser.
I give up, doing calculus suddenly seemed way more easier when trying to make mobile responsive frontend.
There, fixed bugs, and looking good. I want to finish on working on the mobile view so I could test it in the phone before the week ends.
Argh, it's really quite difficult for me when it comes to mobile responsiveness. Things like making sure the text size is right, and all the words and spaces wrap properly. I should properly learn how to do this the right way.
For now, it works enough for me on the desktop. Not on the phone though, it's barely useable with a tiny screen.
Aha, I managed to almost copy the exact popup behaviour of 4chan. Well, almost, then I saw literal some edge case that needs fixing. Oh well, but for the most part, it's looking pretty good. I might actually use this custom HN frontend from now on.
I unproductively tried to imitate the post popup on hover feature on 4chan. The popup works fine, except the positioning is quite tricky to get it right.
Urgh, I can't believe I spent almost an hour finding out what's causing the
<i>100%!&(MISSING)lt;/i>
bug. I though encoding/json was escaping %, but no. I thought gopher-lua was doing some weird string escaping, no again. I thought gopher-luar was doing some weird string escaping, nope.
Then I thought of printing the text right before writing the response back. Curl was showing the broken text, but the printed text shows the text properly.
Aha, by process of elimination, the source of bug was the code writing the response back:
fmt.Fprintf(w, ret.String())
Well of course, fmt uses % to format string, no shit. I feel so retarded now in hindsight.
I tried googling for %!&(MISSING) but it shows me an FBI kidnappings and missing person list, lots of kids too. Uh-oh. Damn, look at all the unresolved cases, some dating back all the way to 2010.
I'm reminded that the world is a scary place, you'll never know what sick fuck is lurking around the corner.
Still mostly worked on making the UI look like *chan forum. I found a bug where some tags wouldn't close and end up like `<i>100%!&(MISSING)lt;/i>`. It doesn't happen with direct curl to HN API, so the problem is most likely my escaping function, or the json parser.
So I noticed that the posts have non-deterministing sorting. I thought, fuck concurrency, I'll just do it without any goroutines, it'll be one http request at a time.
I tried rewriting it, and the code certainly looked simpler. But, it's so, slow. The heck, I thought it would only be a little bit slower, but no, it's about ten times slower on some HN threads.
I undid the rewrite, and just used a map to sort posts by insert order.
Seeing my changes also takes a couple of seconds, so I added some caching to filesystem too, to prevent execessive requests while testing.
I more or less now have a working basic HN frontend. I think I'll make the UI linear like lainchan/4chan, instead of the usual tree view like reddit and HN. Neovim's lspconfig with gopls is giving me some error though, pretty annoying, not even sure how to fix this.
Wrote some code to handle concurrent http requests. It's never easy to write multi-threaded code, as I'm never sure if there's no deadlock lurking somewhere, or some unexpected race condition will happen. For now, it's working as expected, and it "looks" correct.
I decided to use the official HN api while creating the frontend first. That way, it's easier to create a compatible backend later on.
There fixed the __tostring problem by using L.CallByParam. I also had to create my own version of dofile since the one provided by gopher-lua doesn't allow setting the chunk name, and seeing chunk name is important when debugging.
I considered using htmz, but since hacker news doesn't have a lot of UI interactivity, it's not needed for this toy project.
I was wondering why I keep getting a nil pointer dereference, as it turns out, I'm closing L.close() before I could even use L. Now my problem is why the __tostring metamethod isn't being called from the go code. I'm currently looking for code examples how to do that, or just examples how to better use the gopher-lua API.
Worked on getting the lua environment to work with gopher-lua. The custom loader solution works fine, now I just to figure out a way to structure the web application. For demostration purposes, I'll just create a simple HN clone.
So I decided to try making a web application with go and the lua template. After all, that was the original reason why I made moon-temple: so I could have an alternative templating engine text/template that comes with golang.
I've done some playing around with gopher-lua, and I managed to run html.lua. There's one problem though: I want the binaries self-contained as usual, so I needed to use embed.FS. Naturally, gopher-lua doesn't know how to load files from my embedded filesystem, and skimming through the docs, it appears there's no built-in support for doing that.
The first workaround I tried is to just extract the embedded files into the current directory if they are newer or doesn't exist. But strangely, running Stat() on the embedded files always return a 0 timestamp.
The second workaround I'm considering is writing a custom package.loader for lua. I found an example that I could use. Crazy enough, that example shows how I could even extend lua's syntax!? Imagine I could even go further with my DSL madness AHAHA. Or not, the editor LSP would start cussing at me if I did that. Pretty neat stuffs though.
site last updated on 2024-10-16 | created with moontpl